package com.zmc.order.config.mq;


import com.zmc.common.constant.QueueConstant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author zmc
 * 退款
 */
@Configuration
public class RefundQueueConfig {


    /**
     * 创建分单交换机
     */
    @Bean("refundExchange")
    public Exchange refundExchange() {
        return new TopicExchange(QueueConstant.REFUND_EXCHANGE, true, false);
    }

    /**
     * 创建分单队列
     */
    @Bean("refundQueue")
    public Queue refundQueue() {
        return QueueBuilder.durable(QueueConstant.REFUND_QUEUE).build();
    }

    /**
     * 绑定分单交换机和分单队列
     */
    @Bean("refundBinding")
    public Binding refundBinding(@Qualifier("refundQueue") Queue queue, @Qualifier("refundExchange")Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(QueueConstant.REFUND_ROUTING_KEY).noargs();
    }


}
